Skip to content

src: create lazy json parser#61855

Draft
araujogui wants to merge 1 commit intonodejs:mainfrom
araujogui:lazy-json-parser
Draft

src: create lazy json parser#61855
araujogui wants to merge 1 commit intonodejs:mainfrom
araujogui:lazy-json-parser

Conversation

@araujogui
Copy link
Member

No description provided.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/loaders
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Feb 16, 2026
@JakobJingleheimer
Copy link
Member

Is this related to #61641 ?

@araujogui
Copy link
Member Author

Is this related to #61641 ?

Yeah, I decided to pivot. Since full JSON materialization is likely a performance bottleneck, I’m implementing a lazy JSON parser instead.

test('compound root array returns document with type "array"', (t) => {
const parser = new Parser();
const doc = parser.parse('[1, 2, 3]');
t.assert.strictEqual(doc.root().type(), 'array');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't return string from this. This would be extremely slow. We can use an enum of numeric values called JSONType, and to .type() == JSONType.Array

require('../common');

const { test, describe } = require('node:test');
const { Parser } = require('node:json_parser');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why limit the module name to only parser?

Suggested change
const { Parser } = require('node:json_parser');
const { JSONParser } = require('node:json');

Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Docs are missing.
  • Tests handling each edge case (errors) are missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants